package easyjava.hibernate;

import java.util.Arrays;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.ProjectionList;
import org.hibernate.criterion.Projections;

import easyjava.hibernate.bean.Student;

public class CriteriaDemo {

	public static void main(String[] args) {

		try {
			SessionFactory sf = new Configuration().configure().buildSessionFactory();
			Session session = sf.openSession();

			Criteria criteria = session.createCriteria(Student.class);

			List students = criteria.list();

			for (Object o : students) {
				System.out.println(o);
			}

			DetachedCriteria dc = DetachedCriteria.forClass(Student.class);
			Criteria cr = dc.getExecutableCriteria(session);

			System.out.println("=======================Detach Criteria======================== ");
			List student = cr.list();
			for (Object o : student) {
				System.out.println(o);
			}

		} catch (HibernateException e) {
			e.printStackTrace();
		}
	}

}
